// http://www.ziqiangxuetang.com/redis/redis-sets.html
var config = require('../config');
var redis = require("redis"),
configRedis = {
    host: config.redis.host,   // 服务器地址 
    port: config.redis.port,        // 服务器端口 
    password: config.redis.password,         // 服务器端口 
    db: config.redis.db,              // 数据库号码 
},
client = redis.createClient(configRedis);

// var sub = redis.createClient(configRedis);
// var pub = redis.createClient(configRedis);
// var msg_count = 0;

// sub.on("subscribe", function (channel, count) {
//     console.info('channel:',channel);
//     console.info('count:',count);
//     // pub.publish(channel, "asdff");
//     // pub.publish(channel, "I am sending a second message.");
//     // pub.publish(channel, "I am sending my last message.");
// });
 
// sub.on("message", function (channel, message) {
//     console.log("sub channel " + channel + ": " + message);
// });


// // 订阅
// sub.subscribe("push_talk");
// setInterval(function (argument) {
//     pub.publish('push_talk', new Date().getTime());
// },1000)



client.auth(config.redis.password,function(err,doc){});
// if you'd like to select database 3, instead of 0 (default), call 
// client.select(3, function() { /* ... */ }); 
 
client.on("error", function (err) {
    console.log("Redis Error " + err);
});
// client.set('test111','12');
// client.expire('test111',10);
// client.sadd('key2','1');
// client.sadd('key2','2');
// client.sadd('key2','3');
// // 移除集合中一个或多个成员
// client.srem('key2','2');
// // 返回所有给定集合的并集
// client.smembers('key2',function (err, replies) {
// 	console.info('key2 replies:',replies);
// })


// client.hset("key1",'asfsafd' ,{a:1}, redis.print);
// client.hdel("hash key", "hashtest 11", redis.print);
// client.hset("hash key", "hashtest 111212", "some value", redis.print);
// client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
// client.expire('hash key', 13);
// client.hgetall("key1", function (err, replies) {
	// console.info('replies:',replies);
    // console.log(replies.length + " replies:");
    // replies.forEach(function (reply, i) {
    //     console.log("    " + i + ": " + reply);
    // });
    // client.quit();
// });
// client.flushall();
module.exports = client;
